package cn.kevenpotter.leetcode.easy.e225;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack {

    Queue<Integer> rawStack;
    Queue<Integer> assistStack;

    /**
     * Initialize your data structure here.
     */
    public MyStack() {
        rawStack = new LinkedList<Integer>();
        assistStack = new LinkedList<Integer>();
    }

    /**
     * Push element x onto stack.
     */
    public void push(int x) {
        assistStack.offer(x);
        while (!rawStack.isEmpty()) {
            assistStack.offer(rawStack.poll());
        }
        Queue<Integer> temp = rawStack;
        rawStack = assistStack;
        assistStack = temp;
    }

    /**
     * Removes the element on top of the stack and returns that element.
     */
    public int pop() {
        return rawStack.poll();
    }

    /**
     * Get the top element.
     */
    public int top() {
        return rawStack.peek();
    }

    /**
     * Returns whether the stack is empty.
     */
    public boolean empty() {
        return rawStack.isEmpty();
    }
}
